#include<iostream>
#include<algorithm>
#include<list>
using namespace std;

struct Node
{
    int order;
    double val;
};
const int EPS = 1e-5;
int main(int argc, char const *argv[])
{
    freopen("test.txt","r",stdin);
    list<Node> poly[2];
    // input
    for(int i = 0;i<2;++i)
    {
        int K; cin>>K;
        for(int _=0;_<K;++_)
        {
            Node tmp; cin>>tmp.order>>tmp.val;
            poly[i].push_back(tmp);
        }
    }
    // do merge
    list<Node> res;
    list<Node>::iterator p1 = poly[0].begin(),p2 = poly[1].begin();
    while(p1 != poly[0].end() && p2 != poly[1].end())
    {
        if(p1->order > p2->order)
            res.push_back(*p1++); 
        else if(p1->order < p2->order)
            res.push_back(*p2++);
        else
        {
            double tmp = p1->val+p2->val;
            if(tmp>EPS || tmp<EPS)
            {
                Node n{p1->order,tmp};
                res.push_back(n);
            }
            p1++;p2++;
        }
    }
    if(p1!=poly[0].end())
        res.splice(res.end(),poly[0],p1,poly[0].end());
    if(p2 != poly[1].end())
        res.splice(res.end(),poly[1],p2,poly[1].end());

    cout<<res.size();
    for(auto &x:res)
        printf(" %d %.1f",x.order,x.val); 
    return 0;
}
